﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ttlang.builder.cs
{
    static class AutoBuild
    {        /// <summary>
             /// 构建csharp 项目
             /// </summary>
        public static void BuildCSProj(Result result,string path)
        {
            //不同操作系统
            //检查是否安装环境？
            SystemCall.SetWorkingPath(path);
            SystemCall.ClearEnvVar();
            SystemCall.SetEnvVar("DOTNET_CLI_UI_LANGUAGE", "en");


            bool succ = false;
            string pathresult ="";
            SystemCall.Call("dotnet build",

           
            (txt) =>
            {
                if (txt != null)
                {
                    if (txt.IndexOf("Build succeeded") == 0)
                        succ = true;

                    if (txt.Contains("->"))
                    {
                        pathresult = txt.Split("->")[1];
                    }
                    Console.WriteLine(String.Format("dotnet build log: {0}", txt));
                }
            }
            ,
            (txt) =>
            {
                if (txt != null)
                {
                    Console.WriteLine(String.Format("dotnet build error: {0}", txt));
                }
            }
            );

            if(succ)
            {
                result.autobuild = pathresult;
            }
        }

    }
}
